library(tidyverse)
library(magrittr)

rm(list = ls())

Create the file structure for the first 5 plates

# plates and experiments
plate2 <- c(
  "exp_190831",
  "exp_190905",
  "exp_190909",
  "exp_190921",
  "exp_191107"
)
plate3 <- c(
  "exp_190923",
  "exp_191109",
  "exp_191111"
)
plate1 <- c(
  "exp_191115",
  "exp_191116"
)
plate4 <- c(
  "exp_191120",
  "exp_191121"
)
plate5 <- c(
  "exp_191129",
  "exp_191130"
)
plate_exp_list <- list(plate1, plate2, plate3, plate4, plate5)
names(plate_exp_list) <- sapply(1:5, function(x){
  str_c("plate", x)
})
# folders
folders <- c(
  "Growth_curves",
  "Inocula_OD",
  "LDH",
  "PI_endpoints",
  "PI_kinetics",
  "Parameters"
)
# Generate file structure 
directories <- sapply(1:length(plate_exp_list), function(i){
  dir <- str_c("Raw_data/", names(plate_exp_list[i]))
  if (!dir.exists(dir)) dir.create(dir)
  directories <-sapply(plate_exp_list[[i]], function(x){
    dir <- str_c(dir, "/", x)
    if (!dir.exists(dir)) dir.create(dir)
    return(dir)
  })
  return(directories)
})

# Move existing data manually
# plate2 <- c(
#   "exp_190831",
#   "exp_190905",
#   "exp_190909",
#   "exp_190921",
#   "exp_191107"
# )
# plate3 <- c(
#   "exp_190923",
#   "exp_191109",
#   "exp_191111"
# )
# plate1 <- c(
#   "exp_191115",
#   "exp_191116"
# )

# Create folder structure
# vector of directories
directories <- Reduce(c, directories)
purrr::walk(directories, function(x){
  lapply(folders, function(y){
    dir <- str_c(x, "/", y)
    print(str_c("Checking if ", dir, "exists ..."))
    if (!dir.exists(dir)) dir.create(dir)
  })
})
## [1] "Checking if Raw_data/plate1/exp_191115/Growth_curvesexists ..."
## [1] "Checking if Raw_data/plate1/exp_191115/Inocula_ODexists ..."
## [1] "Checking if Raw_data/plate1/exp_191115/LDHexists ..."
## [1] "Checking if Raw_data/plate1/exp_191115/PI_endpointsexists ..."
## [1] "Checking if Raw_data/plate1/exp_191115/PI_kineticsexists ..."
## [1] "Checking if Raw_data/plate1/exp_191115/Parametersexists ..."
## [1] "Checking if Raw_data/plate1/exp_191116/Growth_curvesexists ..."
## [1] "Checking if Raw_data/plate1/exp_191116/Inocula_ODexists ..."
## [1] "Checking if Raw_data/plate1/exp_191116/LDHexists ..."
## [1] "Checking if Raw_data/plate1/exp_191116/PI_endpointsexists ..."
## [1] "Checking if Raw_data/plate1/exp_191116/PI_kineticsexists ..."
## [1] "Checking if Raw_data/plate1/exp_191116/Parametersexists ..."
## [1] "Checking if Raw_data/plate2/exp_190831/Growth_curvesexists ..."
## [1] "Checking if Raw_data/plate2/exp_190831/Inocula_ODexists ..."
## [1] "Checking if Raw_data/plate2/exp_190831/LDHexists ..."
## [1] "Checking if Raw_data/plate2/exp_190831/PI_endpointsexists ..."
## [1] "Checking if Raw_data/plate2/exp_190831/PI_kineticsexists ..."
## [1] "Checking if Raw_data/plate2/exp_190831/Parametersexists ..."
## [1] "Checking if Raw_data/plate2/exp_190905/Growth_curvesexists ..."
## [1] "Checking if Raw_data/plate2/exp_190905/Inocula_ODexists ..."
## [1] "Checking if Raw_data/plate2/exp_190905/LDHexists ..."
## [1] "Checking if Raw_data/plate2/exp_190905/PI_endpointsexists ..."
## [1] "Checking if Raw_data/plate2/exp_190905/PI_kineticsexists ..."
## [1] "Checking if Raw_data/plate2/exp_190905/Parametersexists ..."
## [1] "Checking if Raw_data/plate2/exp_190909/Growth_curvesexists ..."
## [1] "Checking if Raw_data/plate2/exp_190909/Inocula_ODexists ..."
## [1] "Checking if Raw_data/plate2/exp_190909/LDHexists ..."
## [1] "Checking if Raw_data/plate2/exp_190909/PI_endpointsexists ..."
## [1] "Checking if Raw_data/plate2/exp_190909/PI_kineticsexists ..."
## [1] "Checking if Raw_data/plate2/exp_190909/Parametersexists ..."
## [1] "Checking if Raw_data/plate2/exp_190921/Growth_curvesexists ..."
## [1] "Checking if Raw_data/plate2/exp_190921/Inocula_ODexists ..."
## [1] "Checking if Raw_data/plate2/exp_190921/LDHexists ..."
## [1] "Checking if Raw_data/plate2/exp_190921/PI_endpointsexists ..."
## [1] "Checking if Raw_data/plate2/exp_190921/PI_kineticsexists ..."
## [1] "Checking if Raw_data/plate2/exp_190921/Parametersexists ..."
## [1] "Checking if Raw_data/plate2/exp_191107/Growth_curvesexists ..."
## [1] "Checking if Raw_data/plate2/exp_191107/Inocula_ODexists ..."
## [1] "Checking if Raw_data/plate2/exp_191107/LDHexists ..."
## [1] "Checking if Raw_data/plate2/exp_191107/PI_endpointsexists ..."
## [1] "Checking if Raw_data/plate2/exp_191107/PI_kineticsexists ..."
## [1] "Checking if Raw_data/plate2/exp_191107/Parametersexists ..."
## [1] "Checking if Raw_data/plate3/exp_190923/Growth_curvesexists ..."
## [1] "Checking if Raw_data/plate3/exp_190923/Inocula_ODexists ..."
## [1] "Checking if Raw_data/plate3/exp_190923/LDHexists ..."
## [1] "Checking if Raw_data/plate3/exp_190923/PI_endpointsexists ..."
## [1] "Checking if Raw_data/plate3/exp_190923/PI_kineticsexists ..."
## [1] "Checking if Raw_data/plate3/exp_190923/Parametersexists ..."
## [1] "Checking if Raw_data/plate3/exp_191109/Growth_curvesexists ..."
## [1] "Checking if Raw_data/plate3/exp_191109/Inocula_ODexists ..."
## [1] "Checking if Raw_data/plate3/exp_191109/LDHexists ..."
## [1] "Checking if Raw_data/plate3/exp_191109/PI_endpointsexists ..."
## [1] "Checking if Raw_data/plate3/exp_191109/PI_kineticsexists ..."
## [1] "Checking if Raw_data/plate3/exp_191109/Parametersexists ..."
## [1] "Checking if Raw_data/plate3/exp_191111/Growth_curvesexists ..."
## [1] "Checking if Raw_data/plate3/exp_191111/Inocula_ODexists ..."
## [1] "Checking if Raw_data/plate3/exp_191111/LDHexists ..."
## [1] "Checking if Raw_data/plate3/exp_191111/PI_endpointsexists ..."
## [1] "Checking if Raw_data/plate3/exp_191111/PI_kineticsexists ..."
## [1] "Checking if Raw_data/plate3/exp_191111/Parametersexists ..."
## [1] "Checking if Raw_data/plate4/exp_191120/Growth_curvesexists ..."
## [1] "Checking if Raw_data/plate4/exp_191120/Inocula_ODexists ..."
## [1] "Checking if Raw_data/plate4/exp_191120/LDHexists ..."
## [1] "Checking if Raw_data/plate4/exp_191120/PI_endpointsexists ..."
## [1] "Checking if Raw_data/plate4/exp_191120/PI_kineticsexists ..."
## [1] "Checking if Raw_data/plate4/exp_191120/Parametersexists ..."
## [1] "Checking if Raw_data/plate4/exp_191121/Growth_curvesexists ..."
## [1] "Checking if Raw_data/plate4/exp_191121/Inocula_ODexists ..."
## [1] "Checking if Raw_data/plate4/exp_191121/LDHexists ..."
## [1] "Checking if Raw_data/plate4/exp_191121/PI_endpointsexists ..."
## [1] "Checking if Raw_data/plate4/exp_191121/PI_kineticsexists ..."
## [1] "Checking if Raw_data/plate4/exp_191121/Parametersexists ..."
## [1] "Checking if Raw_data/plate5/exp_191129/Growth_curvesexists ..."
## [1] "Checking if Raw_data/plate5/exp_191129/Inocula_ODexists ..."
## [1] "Checking if Raw_data/plate5/exp_191129/LDHexists ..."
## [1] "Checking if Raw_data/plate5/exp_191129/PI_endpointsexists ..."
## [1] "Checking if Raw_data/plate5/exp_191129/PI_kineticsexists ..."
## [1] "Checking if Raw_data/plate5/exp_191129/Parametersexists ..."
## [1] "Checking if Raw_data/plate5/exp_191130/Growth_curvesexists ..."
## [1] "Checking if Raw_data/plate5/exp_191130/Inocula_ODexists ..."
## [1] "Checking if Raw_data/plate5/exp_191130/LDHexists ..."
## [1] "Checking if Raw_data/plate5/exp_191130/PI_endpointsexists ..."
## [1] "Checking if Raw_data/plate5/exp_191130/PI_kineticsexists ..."
## [1] "Checking if Raw_data/plate5/exp_191130/Parametersexists ..."

PI kinetics

Import raw data, one table at the time

source("Functions/parse_results.R")

experiment 190831

# arguments for parse function
file <- "Raw_data/plate2/exp_190831/PI_kinetics/190831 LD PI Assay VANANZ 24 hours.xlsx"
duration <- c(22, 42)
wavelength <- c(493, 535)

# new variables
exp <- "exp190831"
cell_number <- 40e3
plate <- 2

# parse results
data <- parse_kinetics(file = file, duration = duration, wavelength = wavelength, exp = exp, cell_number = cell_number, plate = plate)

data
## # A tibble: 21,888 x 9
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A01      21309         0 A        01       exp190831        40000     2
##  2 A02      20923         0 A        02       exp190831        40000     2
##  3 A03      19649         0 A        03       exp190831        40000     2
##  4 A04      20962         0 A        04       exp190831        40000     2
##  5 A05      20381         0 A        05       exp190831        40000     2
##  6 A06      20933         0 A        06       exp190831        40000     2
##  7 A07      20737         0 A        07       exp190831        40000     2
##  8 A08      21094         0 A        08       exp190831        40000     2
##  9 A09      20141         0 A        09       exp190831        40000     2
## 10 A10      20781         0 A        10       exp190831        40000     2
## # … with 21,878 more rows, and 1 more variable: well_id <chr>
# add to list
kinetics_data <- list()
kinetics_data[[1]] <- data

exp 090905

file <- "Raw_data/plate2/exp_190905/PI_kinetics/190830 HeLa 25000 Cell death rate dynamic.xlsx"
duration <- c(20, 6)
wavelength <- c(493, 535)

# new variables
exp <- "exp190905"
cell_number <- 25e3
plate <- 2

# parse results
# parse results
data <- parse_kinetics(file = file,  duration = duration, wavelength = wavelength, exp = exp, cell_number = cell_number, plate = plate)

data
## # A tibble: 19,392 x 9
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A01       1132         0 A        01       exp190905        25000     2
##  2 A02       1123         0 A        02       exp190905        25000     2
##  3 A03       1143         0 A        03       exp190905        25000     2
##  4 A04       1119         0 A        04       exp190905        25000     2
##  5 A05       1135         0 A        05       exp190905        25000     2
##  6 A06       1130         0 A        06       exp190905        25000     2
##  7 A07       1122         0 A        07       exp190905        25000     2
##  8 A08       1139         0 A        08       exp190905        25000     2
##  9 A09       1127         0 A        09       exp190905        25000     2
## 10 A10       1140         0 A        10       exp190905        25000     2
## # … with 19,382 more rows, and 1 more variable: well_id <chr>
# add to list
kinetics_data[[2]] <- data

exp 190909

file <- "Raw_data/plate2/exp_190909/PI_kinetics/190910.Plate.Vananz.2.HeLa.20000.cell.death.rate.dynamic.run.3.xlsx"
duration <- c(21, 0)
wavelength <- 535

# new variables
exp <- "exp190909"
cell_number <- 20e3
plate <- 2

# parse results
data <- parse_kinetics(file = file,  duration = duration, wavelength = wavelength, exp = exp, cell_number = cell_number, plate = plate)

data
## # A tibble: 20,256 x 9
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A01      27434         0 A        01       exp190909        20000     2
##  2 A02      27092         0 A        02       exp190909        20000     2
##  3 A03      27328         0 A        03       exp190909        20000     2
##  4 A04      27807         0 A        04       exp190909        20000     2
##  5 A05      28502         0 A        05       exp190909        20000     2
##  6 A06      28460         0 A        06       exp190909        20000     2
##  7 A07      29114         0 A        07       exp190909        20000     2
##  8 A08      28506         0 A        08       exp190909        20000     2
##  9 A09      27791         0 A        09       exp190909        20000     2
## 10 A10      28325         0 A        10       exp190909        20000     2
## # … with 20,246 more rows, and 1 more variable: well_id <chr>
# add to list
kinetics_data[[3]] <- data

exp 190921

file <- "Raw_data/plate2/exp_190921/PI_kinetics/190921 HeLa real time cell death assay n4 using 20000 cells .xlsx"
n_skip <- 13
duration <- c(20, 48)
wavelength <- c(493, 535)

# new variables
exp <- "exp190921"
cell_number <- 20e3
plate <- 2

# parse results
data <- parse_kinetics(file = file,  duration = duration, wavelength = wavelength, exp = exp, cell_number = cell_number, plate = plate)

data
## # A tibble: 19,855 x 9
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A02       1141         0 A        02       exp190921        20000     2
##  2 A03       1128         0 A        03       exp190921        20000     2
##  3 A04       1113         0 A        04       exp190921        20000     2
##  4 A05       1112         0 A        05       exp190921        20000     2
##  5 A06       1140         0 A        06       exp190921        20000     2
##  6 A07       1130         0 A        07       exp190921        20000     2
##  7 A08       1124         0 A        08       exp190921        20000     2
##  8 A09       1129         0 A        09       exp190921        20000     2
##  9 A10       1137         0 A        10       exp190921        20000     2
## 10 A11       1145         0 A        11       exp190921        20000     2
## # … with 19,845 more rows, and 1 more variable: well_id <chr>
# add to list
kinetics_data[[4]] <- data

exp 190923

file <- "Raw_data/plate3/exp_190923/PI_kinetics/190923 plate VANANZ 3 HeLa real time cell death n5.xlsx"
n_skip <- 13
duration <- c(22, 18)
wavelength <- 535

# new variables
exp <- "exp190923"
cell_number <- 2e4
plate <- 3

# parse results
data <- parse_kinetics(file = file,  duration = duration, wavelength = wavelength, exp = exp, cell_number = cell_number, plate = plate)

data
## # A tibble: 21,280 x 9
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A02      18722         0 A        02       exp190923        20000     3
##  2 A03      19282         0 A        03       exp190923        20000     3
##  3 A04      19248         0 A        04       exp190923        20000     3
##  4 A05      17418         0 A        05       exp190923        20000     3
##  5 A06      19365         0 A        06       exp190923        20000     3
##  6 A07      18733         0 A        07       exp190923        20000     3
##  7 A08      19039         0 A        08       exp190923        20000     3
##  8 A09      19279         0 A        09       exp190923        20000     3
##  9 A10      18530         0 A        10       exp190923        20000     3
## 10 A11      19106         0 A        11       exp190923        20000     3
## # … with 21,270 more rows, and 1 more variable: well_id <chr>
# add to list
kinetics_data[[5]] <- data

exp 191107

file <- "Raw_data/plate2/exp_191107/PI_kinetics/191107 plate 2  HeLa 40000 real time cell death .xlsx"
n_skip <- 13
duration <- c(24, 54)
wavelength <- 535

# new variables
exp <- "exp191107"
cell_number <- 4e4
plate <- 2

# parse results
data <- parse_kinetics(file = file,  duration = duration, wavelength = wavelength, exp = exp, cell_number = cell_number, plate = plate)

data
## # A tibble: 23,750 x 9
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A02      15166         0 A        02       exp191107        40000     2
##  2 A03      15799         0 A        03       exp191107        40000     2
##  3 A04      15422         0 A        04       exp191107        40000     2
##  4 A05      14969         0 A        05       exp191107        40000     2
##  5 A06      15489         0 A        06       exp191107        40000     2
##  6 A07      15563         0 A        07       exp191107        40000     2
##  7 A08      15241         0 A        08       exp191107        40000     2
##  8 A09      14810         0 A        09       exp191107        40000     2
##  9 A10      15169         0 A        10       exp191107        40000     2
## 10 A11      15094         0 A        11       exp191107        40000     2
## # … with 23,740 more rows, and 1 more variable: well_id <chr>
# add to list
kinetics_data[[6]] <- data

exp 191109

file <- "Raw_data/plate3/exp_191109/PI_kinetics/Vananz plate 3 191109 real time cell death n1.xlsx"
n_skip <- 13
duration <- c(20, 48)
wavelength <- 535

# new variables
exp <- "exp191109"
cell_number <- 4e4
plate <- 3

# parse results
data <- parse_kinetics(file = file,  duration = duration, wavelength = wavelength, exp = exp, cell_number = cell_number, plate = plate)

data
## # A tibble: 19,855 x 9
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A02      16534         0 A        02       exp191109        40000     3
##  2 A03      16349         0 A        03       exp191109        40000     3
##  3 A04      16474         0 A        04       exp191109        40000     3
##  4 A05      16186         0 A        05       exp191109        40000     3
##  5 A06      16385         0 A        06       exp191109        40000     3
##  6 A07      16755         0 A        07       exp191109        40000     3
##  7 A08      16924         0 A        08       exp191109        40000     3
##  8 A09      16307         0 A        09       exp191109        40000     3
##  9 A10      15865         0 A        10       exp191109        40000     3
## 10 A11      17343         0 A        11       exp191109        40000     3
## # … with 19,845 more rows, and 1 more variable: well_id <chr>
# add to list
kinetics_data[[7]] <- data

exp 191111

file <- "Raw_data/plate3/exp_191111/PI_kinetics/Vananz plate 3 191111 real time cell death n2.xlsx"
n_skip <- 13
duration <- c(21, 36)
wavelength <- 535

# new variables
exp <- "exp191111"
cell_number <- 4e4
plate <- 3

# parse results
data <- parse_kinetics(file = file,  duration = duration, wavelength = wavelength, exp = exp, cell_number = cell_number, plate = plate)

data
## # A tibble: 20,615 x 9
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A02      16273         0 A        02       exp191111        40000     3
##  2 A03      15536         0 A        03       exp191111        40000     3
##  3 A04      15774         0 A        04       exp191111        40000     3
##  4 A05      16469         0 A        05       exp191111        40000     3
##  5 A06      16403         0 A        06       exp191111        40000     3
##  6 A07      16158         0 A        07       exp191111        40000     3
##  7 A08      16551         0 A        08       exp191111        40000     3
##  8 A09      15644         0 A        09       exp191111        40000     3
##  9 A10      16452         0 A        10       exp191111        40000     3
## 10 A11      16938         0 A        11       exp191111        40000     3
## # … with 20,605 more rows, and 1 more variable: well_id <chr>
# add to list
kinetics_data[[8]] <- data

exp 191115

file <- "Raw_data/plate1/exp_191115/PI_kinetics/Vananz plate 1 191115 HeLa 40000 real time cell death assay n1.xlsx"
n_skip <- 13
duration <- c(22, 42)
wavelength <- c(493, 535)

# new variables
exp <- "exp191115"
cell_number <- 4e4
plate <- 1

# parse results
data <- parse_kinetics(file = file,  duration = duration, wavelength = wavelength, exp = exp, cell_number = cell_number, plate = plate)

data
## # A tibble: 21,660 x 9
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A02      17160         0 A        02       exp191115        40000     1
##  2 A03      16637         0 A        03       exp191115        40000     1
##  3 A04      17393         0 A        04       exp191115        40000     1
##  4 A05      15767         0 A        05       exp191115        40000     1
##  5 A06      16422         0 A        06       exp191115        40000     1
##  6 A07      16401         0 A        07       exp191115        40000     1
##  7 A08      16895         0 A        08       exp191115        40000     1
##  8 A09      16753         0 A        09       exp191115        40000     1
##  9 A10      16556         0 A        10       exp191115        40000     1
## 10 A11      17113         0 A        11       exp191115        40000     1
## # … with 21,650 more rows, and 1 more variable: well_id <chr>
# add to list
kinetics_data[[9]] <- data

exp 191116

file <- "Raw_data/plate1/exp_191116/PI_kinetics/Vananz plate 1 191116 HeLa 40000 real time cell death assay n2.xlsx"
n_skip <- 13
duration <- c(21, 0)
wavelength <- c(493, 535)

# new variables
exp <- "exp191116"
cell_number <- 4e4
plate <- 1

# parse results
data <- parse_kinetics(file = file,  duration = duration, wavelength = wavelength, exp = exp, cell_number = cell_number, plate = plate)

data
## # A tibble: 20,045 x 9
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A02      18284         0 A        02       exp191116        40000     1
##  2 A03      18787         0 A        03       exp191116        40000     1
##  3 A04      20081         0 A        04       exp191116        40000     1
##  4 A05      16714         0 A        05       exp191116        40000     1
##  5 A06      17366         0 A        06       exp191116        40000     1
##  6 A07      17408         0 A        07       exp191116        40000     1
##  7 A08      17020         0 A        08       exp191116        40000     1
##  8 A09      19013         0 A        09       exp191116        40000     1
##  9 A10      20881         0 A        10       exp191116        40000     1
## 10 A11      20576         0 A        11       exp191116        40000     1
## # … with 20,035 more rows, and 1 more variable: well_id <chr>
# add to list
kinetics_data[[10]] <- data

exp 191120

file <- "Raw_data/plate4/exp_191120/PI_kinetics/Vananz plate 4 191120 real time cell death n1.xlsx"
n_skip <- 13
duration <- c(22, 24)
wavelength <- c(493, 535)

# new variables
exp <- "exp191120"
cell_number <- 4e4
plate <- 4

# parse results
data <- parse_kinetics(file = file,  duration = duration, wavelength = wavelength, exp = exp, cell_number = cell_number, plate = plate)

data
## # A tibble: 21,375 x 9
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A02      24955         0 A        02       exp191120        40000     4
##  2 A03      23923         0 A        03       exp191120        40000     4
##  3 A04      24598         0 A        04       exp191120        40000     4
##  4 A05      24213         0 A        05       exp191120        40000     4
##  5 A06      24037         0 A        06       exp191120        40000     4
##  6 A07      24919         0 A        07       exp191120        40000     4
##  7 A08      23476         0 A        08       exp191120        40000     4
##  8 A09      24488         0 A        09       exp191120        40000     4
##  9 A10      23964         0 A        10       exp191120        40000     4
## 10 A11      25975         0 A        11       exp191120        40000     4
## # … with 21,365 more rows, and 1 more variable: well_id <chr>
# add to list
kinetics_data[[11]] <- data

exp 191121

file <- "Raw_data/plate4/exp_191121/PI_kinetics/Vananz plate 4 191121 real time cell death n2.xlsx"
n_skip <- 13
duration <- c(22, 12)
wavelength <- c(493, 535)

# new variables
exp <- "exp191121"
cell_number <- 4e4
plate <- 4

# parse results
data <- parse_kinetics(file = file,  duration = duration, wavelength = wavelength, exp = exp, cell_number = cell_number, plate = plate)

data
## # A tibble: 21,185 x 9
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A02      16341         0 A        02       exp191121        40000     4
##  2 A03      16322         0 A        03       exp191121        40000     4
##  3 A04      16244         0 A        04       exp191121        40000     4
##  4 A05      16695         0 A        05       exp191121        40000     4
##  5 A06      16459         0 A        06       exp191121        40000     4
##  6 A07      16241         0 A        07       exp191121        40000     4
##  7 A08      16206         0 A        08       exp191121        40000     4
##  8 A09      16052         0 A        09       exp191121        40000     4
##  9 A10      15924         0 A        10       exp191121        40000     4
## 10 A11      16305         0 A        11       exp191121        40000     4
## # … with 21,175 more rows, and 1 more variable: well_id <chr>
# add to list
kinetics_data[[12]] <- data

exp 191129

file <- "Raw_data/plate5/exp_191129/PI_kinetics/Vananz plate 5 191129 real time cell death n1.xlsx"
n_skip <- 13
duration <- c(19, 12)
wavelength <- c(493, 535)

# new variables
exp <- "exp191129"
cell_number <- 4e4
plate <- 5

# parse results
data <- parse_kinetics(file = file,  duration = duration, wavelength = wavelength, exp = exp, cell_number = cell_number, plate = plate)

data
## # A tibble: 18,335 x 9
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A02      16672         0 A        02       exp191129        40000     5
##  2 A03      16671         0 A        03       exp191129        40000     5
##  3 A04      17040         0 A        04       exp191129        40000     5
##  4 A05      16557         0 A        05       exp191129        40000     5
##  5 A06      17419         0 A        06       exp191129        40000     5
##  6 A07      16910         0 A        07       exp191129        40000     5
##  7 A08      16963         0 A        08       exp191129        40000     5
##  8 A09      16865         0 A        09       exp191129        40000     5
##  9 A10      17185         0 A        10       exp191129        40000     5
## 10 A11      17426         0 A        11       exp191129        40000     5
## # … with 18,325 more rows, and 1 more variable: well_id <chr>
# add to list
kinetics_data[[13]] <- data

exp 191130

file <- "Raw_data/plate5/exp_191130/PI_kinetics/Vananz plate 5 191130 real time cell death n2.xlsx"
n_skip <- 13
duration <- c(24, 48)
wavelength <- c(493, 535)

# new variables
exp <- "exp191130"
cell_number <- 4e4
plate <- 5

# parse results
data <- parse_kinetics(file = file,  duration = duration, wavelength = wavelength, exp = exp, cell_number = cell_number, plate = plate)

data
## # A tibble: 23,655 x 9
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A02      18720         0 A        02       exp191130        40000     5
##  2 A03      18761         0 A        03       exp191130        40000     5
##  3 A04      18578         0 A        04       exp191130        40000     5
##  4 A05      18881         0 A        05       exp191130        40000     5
##  5 A06      18095         0 A        06       exp191130        40000     5
##  6 A07      18832         0 A        07       exp191130        40000     5
##  7 A08      18985         0 A        08       exp191130        40000     5
##  8 A09      18136         0 A        09       exp191130        40000     5
##  9 A10      19327         0 A        10       exp191130        40000     5
## 10 A11      18031         0 A        11       exp191130        40000     5
## # … with 23,645 more rows, and 1 more variable: well_id <chr>
# add to list
kinetics_data[[14]] <- data

exp 191205

file <- "Raw_data/plate6/exp_191205/PI_kinetics/191205 plate vananz 6 HeLa 40000 cell death rate n1.xlsx"
n_skip <- 13
duration <- c(22, 30)
wavelength <- 535

# new variables
exp <- "exp191205"
cell_number <- 4e4
plate <- 6

# parse results
data <- parse_kinetics(file = file,  duration = duration, wavelength = wavelength, exp = exp, cell_number = cell_number, plate = plate)

data
## # A tibble: 21,470 x 9
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A02      15992         0 A        02       exp191205        40000     6
##  2 A03      16204         0 A        03       exp191205        40000     6
##  3 A04      16689         0 A        04       exp191205        40000     6
##  4 A05      16035         0 A        05       exp191205        40000     6
##  5 A06      16630         0 A        06       exp191205        40000     6
##  6 A07      16469         0 A        07       exp191205        40000     6
##  7 A08      16957         0 A        08       exp191205        40000     6
##  8 A09      16034         0 A        09       exp191205        40000     6
##  9 A10      16141         0 A        10       exp191205        40000     6
## 10 A11      17115         0 A        11       exp191205        40000     6
## # … with 21,460 more rows, and 1 more variable: well_id <chr>
# add to list
kinetics_data[[15]] <- data

exp 191206

file <- "Raw_data/plate6/exp_191206/PI_kinetics/191206 plate vananz 6 HeLa 40000 cell death rate n2.xlsx"
n_skip <- 13
duration <- c(24, 36)
wavelength <- 535

# new variables
exp <- "exp191206"
cell_number <- 4e4
plate <- 6

# parse results
data <- parse_kinetics(file = file,  duration = duration, wavelength = wavelength, exp = exp, cell_number = cell_number, plate = plate)

data
## # A tibble: 23,465 x 9
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A02      18845         0 A        02       exp191206        40000     6
##  2 A03      20015         0 A        03       exp191206        40000     6
##  3 A04      18699         0 A        04       exp191206        40000     6
##  4 A05      18671         0 A        05       exp191206        40000     6
##  5 A06      19672         0 A        06       exp191206        40000     6
##  6 A07      18883         0 A        07       exp191206        40000     6
##  7 A08      18522         0 A        08       exp191206        40000     6
##  8 A09      18891         0 A        09       exp191206        40000     6
##  9 A10      18343         0 A        10       exp191206        40000     6
## 10 A11      19335         0 A        11       exp191206        40000     6
## # … with 23,455 more rows, and 1 more variable: well_id <chr>
# add to list
kinetics_data[[16]] <- data

Merge the dataframes

kinetics_dat <- bind_rows(kinetics_data)
file <- "Data_parsing/dataframes/all_PI_kinetics.csv"
write_csv(kinetics_dat, file)

# Merge with isolate metadata

# Get pair info (= group)
group_info <- read_csv("plate_info/sample_list_plate.csv") %>%
  mutate(sample_id = mdu_id,
         strain_group = studyid) %>%
  select(sample_id, strain_group)
# Get well info and merge with group info
well_info <- read_csv("plate_info/well_info_n843.csv") %>%
  select(well, sample_id, replicate, plate = plate_number) %>%
  # We no longer use TOX-5 as positive toxicity control
  mutate(sample_id = if_else(sample_id == "TOX-5",
                             "JE2", sample_id)) %>%
  # We use max PI signal (lysis of all cells) instead of total LDH
  mutate(sample_id = if_else(sample_id == "Total LDH",
                             "Complete lysis", sample_id)) %>%
  # Replace "blank" with "non infected"
  mutate(sample_id = if_else(sample_id == "Blank",
                             "Non infected", sample_id)) %>%
  left_join(group_info) %>%
  replace_na(list(strain_group = "CONTROL"))
well_info
## # A tibble: 2,976 x 5
##    well  sample_id    replicate plate strain_group
##    <chr> <chr>            <dbl> <dbl> <chr>       
##  1 A01   BPH2722              2     1 VAN-019     
##  2 A02   BPH2712              3     1 VAN-010     
##  3 A03   BPH2700              1     1 VAN-001     
##  4 A04   BPH2711              1     1 VAN-009     
##  5 A05   Non infected         3     1 CONTROL     
##  6 A06   BPH2714              1     1 VAN-011     
##  7 A07   BPH2704              2     1 VAN-004     
##  8 A08   BPH2727              1     1 VAN-023     
##  9 A09   BPH2719              2     1 VAN-016     
## 10 A10   BPH2716              3     1 VAN-013     
## # … with 2,966 more rows
df_kinetics <- kinetics_dat %>%
  left_join(well_info)
  
df_kinetics
## # A tibble: 338,081 x 12
##    well  f_signal timepoint well_row well_col experiment cell_number plate
##    <chr>    <dbl>     <dbl> <chr>    <chr>    <chr>            <dbl> <dbl>
##  1 A01      21309         0 A        01       exp190831        40000     2
##  2 A02      20923         0 A        02       exp190831        40000     2
##  3 A03      19649         0 A        03       exp190831        40000     2
##  4 A04      20962         0 A        04       exp190831        40000     2
##  5 A05      20381         0 A        05       exp190831        40000     2
##  6 A06      20933         0 A        06       exp190831        40000     2
##  7 A07      20737         0 A        07       exp190831        40000     2
##  8 A08      21094         0 A        08       exp190831        40000     2
##  9 A09      20141         0 A        09       exp190831        40000     2
## 10 A10      20781         0 A        10       exp190831        40000     2
## # … with 338,071 more rows, and 4 more variables: well_id <chr>,
## #   sample_id <chr>, replicate <dbl>, strain_group <chr>
file <- "Data_parsing/dataframes/all_PI_kinetics_well_info.csv"
write_csv(df_kinetics, file)

Plot plates

We using a function to plot all replicates together and generate a fitted growth curve.

source("Functions/plot_results.R")

# devtools::install_github("briandconnelly/growthcurve", build_vignettes = TRUE)

# Plot plates
plot_toxicity(df = df_kinetics, plate_number = 2)

plot_toxicity(df = df_kinetics, plate_number = 3)

plot_toxicity(df = df_kinetics, plate_number = 1)

plot_toxicity(df = df_kinetics, plate_number = 4)

plot_toxicity(df = df_kinetics, plate_number = 5)

plot_toxicity(df = df_kinetics, plate_number = 6)